﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class Admin_AddNews : System.Web.UI.Page
{
    AccessDAO dao = new AccessDAO();
    protected void Page_Load(object sender, EventArgs e)
    {
        IsAdmin.Admin();
        if (!Page.IsPostBack)
        {
            int typeid = Convert.ToInt32(Session["xwId"].ToString());
            string sql = "select * from newMessInfo where typeid=" + typeid;
            DataSet ds = dao.getDs(sql);
            foreach (DataRow dr in ds.Tables["message"].Rows)
            {
                this.drpType.Items.Add(dr["typeName"].ToString());
            }
            this.DateTimePicker1.Text = DateTime.Now.ToShortDateString();
        }
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        //int num = 1;
        int typeid = Convert.ToInt32(Session["xwId"].ToString());
        string name = this.txtTitle.Text;
        string typename = drpType.SelectedValue;
        DateTime tt = Convert.ToDateTime(this.DateTimePicker1.Text.ToString());
        string time = tt.ToShortDateString();

        string content = this.FCKeditor1.Value;

        string sql = "insert into newMessage(title,typename,content,newtime,tyid) values('" + name + "','" + typename + "','" + content + "','" + time + "','" + typeid + "')";
        if (!name.Equals(""))
        {
            if (dao.getComm(sql) != 0)
            {
                Server.Transfer("newsMessage.aspx");
            }
            else
            {
                RegisterStartupScript("check", "<script language='javascript'>alert('添加失败');</script>");
            }
        }
        else
        {
            RegisterStartupScript("check", "<script language='javascript'>alert('请填写完整');</script>");
        }
    }

    //取消
    protected void Button1_Click(object sender, EventArgs e)
    {
        Server.Transfer("newsMessage1.aspx");
    }
}

